var data = [{
  id: 1,
  field1: 'qqqqqqq',
  field2: '222',
  field3: '333',
  field4: '222',
}, {
  id: 2,
  field1: 'wwwwwwww',
  field2: '222',
  field3: '333',
  field4: '222',
}, {
  id: 3,
  field1: 'eeeeeeeeeeeee',
  field2: '222',
  field3: '333',
  field4: '222',
}, {
  id: 4,
  field1: 'rrrrrrrrrrrrrrrrrrrrr',
  field2: '222',
  field3: '333',
  field4: '222',
}];

var data1 = [
  {
    id: 1,
    field1: '2014.02.12',
    field2: '审批未通过',
    field3: '张三',
    field4: '质控部',
    field5: '格式不正确',
    field6: '2014.03.10',
  },
]


function getDetailById(id) {
var data = [{
  id:1,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分',
  status: 0
}, {
  id:2,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分',
  status: 1
}, {
  id:3,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分',
  status: 2
}, {
  id:4,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分',
  status: 3  
}, {
  id:5,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分',
  status: 3  
}, {
  id:6,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分',
  status: 2  
}, {
  id:7,
  field0: 'RW1990001201',
  field1: '华天小区建筑材料检测',
  field2: '交通工程-沥青混合料-乳化沥青残留物含量',
  field3: '张三',
  field4: '2016-05-02 12：00',
  field5: '试验中',
  field6: '1天2小时2分'
}];
  var obj = null;
  $.each(data, function(index, value) {
    if (id == value.id) {
      obj = value;
    }
  });

  if(obj == null) {
     return;
  };

  if (obj.status == 1) {
    $("#status1").show();
    $("#status0").hide();
  };

  if (obj.status == 2) {
    $("#status2").show();
  };

  if (obj.status == 3) {
    $("#status3").show();
  };

};


/**
 * 表格初始化
 */
function initTable(newParams) {
  var $table = $('#table1');
  $table.bootstrapTable({
    url: "",
    method: 'POST',
    pagination: true,
    pageSize: 10,
    sidePagination: 'server', //设置为服务器端分页
    queryParams: function(params) {
      // 请求参数
      var obj = {
        size: params.limit,
        page: params.offset / params.limit + 1
      };
      return JSON.stringify(obj);
    }
  });
};

$(document).ready(function() {
  var $table = $('#table1');
  $table.bootstrapTable({
    data: data1,
    pagination: true
  });

  getDetailById(getQueryString("id"));

  initWebUploader();
});


function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}


function initWebUploader() {
        var uploader = WebUploader.create({
          server: '#',
          pick: {
            "id":'#selectImg',   
            "multiple":false   //禁止多选。     
          },  
          auto: true,
          //分片上传设置
          chunked:true,  //允许分片
          chunkSize:2*1024*1024, //每片大小2M
          chunkRetry:4,  //分片上传失败之后的重试次数
          threads:3,  //上传并发数。允许同时最大3个上传进程
          duplicate:true,

          //上传文件个数限制
          fileNumLimit:1,
          //单个文件大小限制  20M
          fileSingleSizeLimit:20*1024*1024,
          accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
          },  
          thumb: {
              width: 200,
              height: 200,
              quality: 100,
              allowMagnify: false,
              crop: true,
              type: 'image/jpeg'
          } ,             
      });

      uploader.on( 'fileQueued', function( file ) {
    
              uploader.makeThumb( file, function( error, ret ) {
                $("#selectImgDiv").empty();
                     if ( error ) {
                      $("#selectImgDiv").append('<label>预览错误</label>');
                     } else {
                          $("#selectImgDiv").append('<img alt="" src="' + ret + '" />');
                     }
              });
      });

       uploader.on( 'uploadComplete', function( file ) {
                console.log("uploadComplete");
                 uploader.reset();
       });
      uploader.on( 'uploadSuccess', function( file ) {
                console.log("uploadSuccess");
       });
       uploader.on( 'uploadError', function( file ) {
                console.log("uploadError");
       });
}